class Toast extends egret.DisplayObjectContainer {
    /**
     * 提示
     * msg为提示语
     * during为多少秒后隐藏
    */
    private msg:string = "错误";
    private during:number = 0;
    private showTimeout;
	public constructor(msg,during) {
		super();
        this.msg = msg;
        this.during = during;
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
	}
    
    private onAddToStage(){
        this.init();
    }

    private init(){
        let bg = new egret.Bitmap();
        bg.texture = RES.getRes("msg_bg_png");
        this.addChild(bg);
        this.width = 505; 
        this.height = 59;
        let _y = Utils.stageH / 6;
        this.x = (Utils.stageW - this.width )/2;
        this.y = 0;
        this.alpha = 0;
        var label:egret.TextField = new egret.TextField(); 
        label.text = this.msg; 
        label.width = this.width;
        label.size = 22;
        label.y = 18;
        label.textAlign = "center"
        this.addChild( label );
        egret.Tween.get(this, { loop: false }).to({y:_y ,alpha:1},400,egret.Ease.backOut);
        if(this.during>0){
            this.showTimeout = setTimeout(()=>{
                this.removeToast();
            },this.during)
        }
    }

    //移除loading
    public removeToast(){
        this.removeChildren();
        try{
            clearTimeout(this.showTimeout);
            egret.Tween.removeTweens(this);
        }catch(e){}
        if(this.parent){
            this.parent.removeChild(this);
        }
    }
}